#include <stdio.h>
#include <math.h>
#define N 10

//无穷范数
double habs(double x[])
{
	int i;
	double max = 0;
	for(i = 0;i < N;i++)
	{
		if(fabs(x[i]) > max)
			max = fabs(x[i]);
	}
	return max;
}

void SOR(double w)
{
	int n = N;
	int i,j;
	double a[n][n];
	double b[n];
	double x[n];
	double y[n];
	double t[n];
	double min = 0.0001;
	//形成Hilbert 矩阵和b向量	
	for(i = 0;i < n;i++)
	{
		for(j = 0;j < n;j++)
			a[i][j] = 1.0/(i+j+1.0);
		b[i] = 1.0/(i+1);
		x[i] = 0;
	}
	//SOR迭代法	
	do
	{
		for(i = 0;i < n;i++)
			y[i] = x[i];
		for(i = 0;i < n;i++)
		{
			int t;
			 t = b[i];
			for(j = 0;j < i;j++)
				t -= a[i][j]*y[j];
			for(j = i+1;j < n;j++)
				t -= a[i][j]*y[j];
			x[i] = (1-w)*x[i] + w*t/a[i][i];
		}
		for(i = 0;i < n;i++)
			t[i] = x[i] - y[i];
	} while(habs(t) > min);
	for(i = 0;i < n;i++)
		printf("%.10f\n",x[i]);
}

int main()
{
	SOR(1);
	return 0;
}
